﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;

namespace CSBackup_Web.Sources.Legacy
{
    /// <summary>
    /// 原ToolFileOperation类的导出类
    /// </summary>
    class ToolFileOperation
    {
        //导出的宏常量(全部重定义为类域字符串常量，值保持与dll里对应宏的值一致)

        //导出的常量(与宏一样采用重定义值不变的方式)

        //导出的全局变量(与宏导出方式一样)

        //导出的函数
        [DllImport("SecureAutoBackup.dll", EntryPoint = "TFO_MakeDirectory", CharSet = CharSet.Ansi)]
        public extern static int MakeDirectory(string path);

        [DllImport("SecureAutoBackup.dll", EntryPoint = "TFO_DelDirectory", CharSet = CharSet.Ansi)]
        public extern static int DelDirectory(string path);

        [DllImport("SecureAutoBackup.dll", EntryPoint = "TFO_GetFilePath", CharSet = CharSet.Ansi)]
        public extern static int GetFilePath(string file, StringBuilder path);

        [DllImport("SecureAutoBackup.dll", EntryPoint = "TFO_CheckFileExist", CharSet = CharSet.Ansi)]
        public extern static int CheckFileExist(string file);

        [DllImport("SecureAutoBackup.dll", EntryPoint = "TFO_CheckFolderExist", CharSet = CharSet.Ansi)]
        public extern static int CheckFolderExist(string folder);

      
        //添加的函数
        public static bool IsValidPath(string path)
        {
            if (string.Empty == path)
                return false;

            return (1 == CheckFolderExist(path));
        }

        public static bool IsSameDirectory(string lhsPath, string rhsPath)
        {
            if ((null == lhsPath) || (null == rhsPath))
                return false;

            //C#里同一目录的路径字符串末尾可能有“\”也可能没有，统一以没有“\”形式来比较
            lhsPath = lhsPath.TrimEnd(new char[] {'\\'});
            rhsPath = rhsPath.TrimEnd(new char[] {'\\'});

            return (lhsPath == rhsPath);
        }
    }//end of class
}
